package com.wl.jetpackdemo

import android.util.Log
import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.wl.jetpackdemo.base.db.DBManager
import com.wl.jetpackdemo.base.db.user.User
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext

import org.junit.Test
import org.junit.runner.RunWith

import org.junit.Assert.*

/**
 * Instrumented test, which will execute on an Android device.
 *
 * See [testing documentation](http://d.android.com/tools/testing).
 */
@RunWith(AndroidJUnit4::class)
class ExampleInstrumentedTest {
    @Test
    fun useAppContext() {
        // Context of the app under test.
        val appContext = InstrumentationRegistry.getInstrumentation().targetContext
        assertEquals("com.wl.jetpackdemo", appContext.packageName)

        DBManager.init(appContext)
        GlobalScope.launch {
            val users = withContext(Dispatchers.IO) {
                DBManager.db().userDao().insert(User(name = "test1", age = 1, desc = "单元测试1"))
                DBManager.db().userDao().getAll()
            }

            for(user in users) {
                Log.d("WLTest", "user ${user.id
                }, name: ${user.name} : ${user.age}, desc: ${user.desc}")
            }
        }

    }



}